{extend name="base" /}
{block name="body"}
<!--<div class="layui-card layadmin-header">-->
<!--<div class="layui-breadcrumb">-->
<!--<a href="#">首页</a>-->
<!--<span>/</span>-->
<!--</div>-->
<!--</div>-->
<div class="layui-card">
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('admin/admin_user/index')}">管理员</a></li>
            <li class=""><a href="{:url('admin/admin_user/add')}">添加管理员</a></li>
            <li class="layui-this">编辑管理员</li>
        </ul>
        <div class="layui-tab-content">
            <form class="layui-form form-container" action="{:url('admin/admin_user/update')}" method="post">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" value="{$admin_user.username}" required  lay-verify="required" placeholder="请输入用户名" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名/昵称</label>
                    <div class="layui-input-block">
                        <input type="text" name="truename" value="{$admin_user.truename}" required lay-verify="required" placeholder="请输入姓名/昵称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" value="" placeholder="（选填）如不修改则留空" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">重复密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="confirm_password" value="" placeholder="（选填）如不修改则留空" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="status" value="1" title="启用" {if condition="$admin_user.status==1"} checked="checked"{/if}>
                        <input type="radio" name="status" value="0" title="禁用" {if condition="$admin_user.status==0"} checked="checked"{/if}>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">所属权限组</label>
                    <div class="layui-input-block">
                        <select name="group_id" lay-verify="required"  lay-filter="admin_user_group">
                            {foreach name="auth_group_list" item="vo"}
                            <option value="{$vo.id}" {if condition="$admin_user.group_id==$vo.id"} selected="selected"{/if}>{$vo.title}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-form-item-authcitys" {neq name="$admin_user.group_id" value="3"} style="display: none;"{/neq}>
                    <label class="layui-form-label">管理城市</label>
                    <div class="article_tags layui-input-block">
                        <div id="adminuser_auth_citys" class="fl" style="margin-right: 10px;">
                            {volist name="admin_user.auth_regions_arr" id="v"}
                            <p class="item layui-btn layui-btn-primary" cityid="{$v.id}">{$v.name} <i class="layui-icon remove-tag-btn">ဆ</i></p>
                            {/volist}
                        </div>
                        <input type="hidden" value="{$admin_user.auth_regions}" name="auth_regions" id="adminuser_auth_citys_input">
                        <p class="item layui-btn layui-btn-primary layer_authcitys" click="adminuser_auth_citys" assign="adminuser_auth_citys_input" type="multi" id="layer_authcitys" >
                            <i class="layui-icon add-tag-btn">&#x1006;</i>
                        </p>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="hidden" name="id" value="{$admin_user.id}">
                        <button class="layui-btn" lay-submit lay-filter="*">更新</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>

    </div>
</div>

{/block}
{block name="js"}
<script>
    var citysnamearr = {$admin_user.auth_regions_json};
    form.on('select(admin_user_group)', function(data){
        if(data.value == 3){
            $(".layui-form-item-authcitys").show();
        }else{
            $(".layui-form-item-authcitys").hide();
            $("#adminuser_auth_citys_input").val('');
            $("#adminuser_auth_citys").html('');
            citysnamearr = [];
        }
    });



    $('#adminuser_auth_citys').on('click', '.item', function () {
        var _id = parseInt($(this).attr('cityid'));
        var _citys = JSON.parse('[' + $("#adminuser_auth_citys_input").val().split(',')+ ']');
        var _citys_index = _citys.indexOf(_id);
        if(_citys_index> -1){
            $(this).remove();
            _citys.splice(_citys_index, 1);
            citysnamearr.forEach(function (item,index) {
                if(item.id == _id){
                    citysnamearr.splice(index, 1);
                }
            })
            $("#adminuser_auth_citys_input").val(_citys)
        }else{
            layer.msg('出错，请联系技术人员');
        }
    })
</script>
{/block}